﻿CREATE PROCEDURE [dbo].[UpdateComment]
	@CommentId uniqueidentifier,
	@Text nvarchar(max),
	@Priority int,
    @IsDeleted bit,
	@LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE Comment

	SET 
	 
	 [Text] = @Text,
	 [Priority] = @Priority,
	 IsDeleted = @IsDeleted, 
	 LastChanged = @LastChanged,
	 LastChangedBy = @LastChangedBy

	WHERE CommentId = @CommentId AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM Comment 

	WHERE CommentId = @CommentId

RETURN 0